<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>使用for循环打印杨辉三角</title>
    <style>
      span {
        color: white;
      }
    </style>
  </head>
  <body>
    <script>
      function triangle(row = 5) {
        for (let i = 1; i < row; i++) {
          for (let n = row - i; n > 0; n--) {
            document.write('<span>&nbsp;</span>')
          }
          for (let m = i * 2 - 1; m > 0; m--) {
            document.write('*')
          }
          document.write('<br/>')
        }
      }
      triangle()
    </script>
  </body>
</html>
